package win.bitterwine.aspect;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smart4j.framework.aop.AspectProxy;
import org.smart4j.framework.aop.annotation.Aspect;
import org.smart4j.framework.mvc.annotation.Action;

import java.lang.reflect.Method;

/**
 * Created by Administrator on 2017/6/16.
 */
@Aspect(annotation = Action.class)
public class AspectAction extends AspectProxy {
    private static final Logger logger = LoggerFactory.getLogger(AspectAction.class);

    private long begin;

    /**
     *如果都是用json的形式获取数据,则可以使用下方俩个方法进行redis的缓存思路
     * 在before方法中判断是否有缓存(思考怎样)
     */

    @Override
    public void before(Class<?> cls, Method method, Object[] params) throws Throwable {
        logger.debug("---------- begin ----------");
//        begin = System.currentTimeMillis();
//        Class<?> returnType = method.getReturnType();
//        System.out.println(cls);
//        System.out.println(returnType);
        System.out.println("开始:"+begin);
    }

    @Override
    public void after(Class<?> cls, Method method, Object[] params, Object result) throws Throwable {
        logger.debug("time: " + (System.currentTimeMillis() - begin) + "ms");
        logger.debug("----------- end -----------");
//        System.out.println(result.toString());
//        System.out.println("结束:"+System.currentTimeMillis());
//        if(result instanceof Result){
//            System.out.println("是Result的实例..................");
//        }
    }
}
